import re


def clean_text(uncleaned: str):
    # 定义多个正则表达式模式
    patterns = [
        r'\n',  # 匹配换行符
        r'<[^>]*>',  # 匹配 HTML 标签
        r'[*#@&%$!~^\(\){}\[\]|\\/<>]'
    ]

    # 将多个模式合并成一个正则表达式
    combined_pattern = '|'.join(patterns)
    try:
        if "Human:" in uncleaned:
            pattern = r".*?(?=Human:)"

            uncleaned = re.findall(pattern, uncleaned, re.DOTALL)[0]
    except:
        pass
    cleaned_text = re.sub(r'\s+', ' ', uncleaned)
    # 对数据进行替换
    cleaned_text = re.sub(combined_pattern, '', cleaned_text)
    return cleaned_text
